# accessors.py

import functools

class attr_accessor(object):
    def __init__(self, attr_name):
        self.attr_name = attr_name

    def get_attr_name(self):
        return self.attr_name

    def get(self, obj):
        return getattr(obj, self.get_attr_name(), None)

    def set(self, obj, text):
        attr_name = self.get_attr_name()
        if text is '':
            if hasattr(obj, attr_name):
                delattr(obj, attr_name)
                self.del_other_attrs(obj)
        else:
            setattr(obj, attr_name, text)
            self.set_other_attrs(obj, text)

    def del_other_attrs(self, obj):
        pass

    def set_other_attrs(self, obj, text):
        pass

class one_way_accessor(attr_accessor):
    def __init__(self, conv_fn, attr_name):
        attr_accessor.__init__(self, attr_name)
        self.conv_fn = conv_fn

    def get_attr_name(self):
        return self.attr_name + "_str"

    def del_other_attrs(self, obj):
        delattr(obj, self.attr_name)

    def set_other_attrs(self, obj, text):
        setattr(obj, self.attr_name, self.conv_fn(text))

# param_accessor = functools.partial(one_way_accessor, parse_param)

